<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('上传档案')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-employee-uploadfiles" th:object="${employee}">
        <input name="employeeId" th:field="*{employeeId}" type="hidden">
        <div class="form-group">
            <p class="form-control-static"><h5>请上传人员档案：(文件类型仅限为pdf，且不超过10M)</h5></p>
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-4">
                <input type="file" name="file">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input id="btn-uploadfiles" type="button" class="btn btn-primary" value="上传" />
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var prefix = ctx + "system/employee";
    // function submitHandler() {
    //     if ($.validate.form()) {
    //         $.operate.save(prefix + "/transferpost", $('#form-employee-transferpost').serialize());
    //     }
    // }
    var data = new FormData($("#form-employee-uploadfiles")[0]);
    $("#btn-uploadfiles").click(function (){
        $.ajax({
            url: prefix + "/uploadfiles",
            type:"POST",
            data:new FormData($("#form-employee-uploadfiles")[0]),
            processData:false,//处理数据的形式，关闭处理数据（默认以字符串处理）
            contentType:false,//提交数据的形式，关闭默认提交数据的形式（默认以字符串提交）
            dataType:"JSON",
            success:function (json){
                // $.modal.msgSuccess("上传成功！")
                if(json.code===0){
                    // alert("档案上传成功！");
                    $.modal.msgSuccess(json.msg);
                    // //将服务器端返回的头像地址设置img标签的src属性上
                    // $("#img-avatar").attr("src",json.data);//attr（属性，属性值）：给某个属性设置某个值
                    // //将头像保存在cookie中
                    // $.cookie("avatar",json.data,{expires:7});
                }else {
                    $.modal.msgError("请检查文档的类型（pdf）及大小（小于10M）！");
                }
                // $.operate.submit(prefix + "/uploadfiles", "post", "json", data);
            },
            // error:function (xhr){
            //     $.modal.alertError("上传档案时产生未知的异常"+xhr.message);
            // }
        });
    });
</script>
</body>
</html>